package com.syni.mdd.yhd.common.all.dao.jpa;

import com.syni.mdd.yhd.common.all.dao.BaseJPADao;
import com.syni.mdd.yhd.common.all.entity.BmsBusiness;
import com.syni.mdd.yhd.common.all.entity.BmsUserBusinessFocus;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Map;
import java.util.Set;

public interface BmsUserBusinessFocusDao extends BaseJPADao<BmsUserBusinessFocus,Integer> {

    BmsUserBusinessFocus findByBmsUserIdAndBmsBusinessId(Integer userId,Integer businessId);

    List<BmsUserBusinessFocus> findByBmsUserId(Integer userId,Pageable pageable);

    List<BmsUserBusinessFocus> findByBmsUserId(Integer userId);

    @Query(value="select bubf.bms_user_id,bu.login_name,bu.head_img,bubf.new_time from bms_user_business_focus bubf left join bms_user bu on bubf.bms_user_id = bu.id " +
            "where bubf.bms_business_id = ?1 order by bubf.new_time desc,bubf.id desc",nativeQuery=true)
    List<Map<String,Object>> sendFindBusinessFocus(Integer businessId,Pageable pageable);

    /*查询商家的粉丝数*/
    @Query(value = "select count(bubf.id) from bms_user_business_focus bubf where bubf.bms_business_id = ?1",nativeQuery = true)
    Integer selfFindBusinessFocusNum(Integer businessId);

    List<BmsUserBusinessFocus> findByBmsBusinessId(Integer businessId);

    List<BmsUserBusinessFocus> findByBmsUserIdIn(Set<Integer> userIds);
}
